﻿using KeaoBase;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace KeaoMDS.InfoManage
{
    public partial class PeiBiGuanLi : BaseForm
    {
        public PeiBiGuanLi()
        {
            InitializeComponent();
        }

        private void PeiBiGuanLi_Load(object sender, EventArgs e)
        {
            date_kaishishijian.Value = DateTime.Today;
            dataGridView1.AutoGenerateColumns = false;
            BindInfo();
        }

        private void btn_search_Click(object sender, EventArgs e)
        {
            BindInfo();
        }

        private void BindInfo()
        {
            string createCondition = KeaoUtils._DB.CreateAndCondition("peibiriqi", DataValueCommonType.日期时间, string.Format("{0} 00:00:00", date_kaishishijian.Text), string.Format("{0} 23:59:59", date_kaishishijian.Text), SearchConditionType.between);
            createCondition += KeaoUtils._DB.CreateAndCondition("peibileixing", DataValueCommonType.字符串, "水稳料", "", SearchConditionType.等于);
            Dictionary<string, string> orderBys = new Dictionary<string, string>();
            orderBys.Add("peibiriqi", "desc");
            orderBys.Add("gongcheng", "asc");
            orderBys.Add("guanlianwuliao","asc");
            DataTable Dt1 = KeaoUtils._DB.GetDataTableByCondition("tbl_peihebi", createCondition,orderBys);
            dataGridView1.DataSource = Dt1;
        }

        private void menu_1_xinzeng_Click(object sender, EventArgs e)
        {
            //新增
            PeiHeBiBianJi peiHeBiBianJi = new PeiHeBiBianJi();
            peiHeBiBianJi.ShowDialog();
            BindInfo();

        }

        private void menu_1_xiugai_Click(object sender, EventArgs e)
        {
            if (tabControl1.SelectedIndex == 0)
            {
                if (dataGridView1.SelectedRows.Count == 0)
                {
                    return;
                }
                PeiHeBiBianJi peiHeBiBianJi = new PeiHeBiBianJi(tabControl1.SelectedIndex, dataGridView1.SelectedRows[0]);
                if (peiHeBiBianJi.ShowDialog() == DialogResult.OK)
                {
                    BindInfo();
                }
            }
        }

        private void menu_1_shanchu_Click(object sender, EventArgs e)
        {
            if (tabControl1.SelectedIndex == 0)
            {
                if (dataGridView1.SelectedRows.Count == 0)
                {
                    return;
                }
                if (KeaoUtils.ShowQuestionMessage("确定要删除水稳料配合比信息吗？") == DialogResult.Yes)
                {
                    TableRow delRow = new TableRow() { TableName = "tbl_peihebi", ID = string.Format("{0}", dataGridView1.SelectedRows[0].Cells["col_shuiwenliao_id"].Value) };
                    if (KeaoUtils._DB.DeleteRowByID(delRow) > 0)
                    {
                        BindInfo();
                    }
                }
            }
        }

        private void dataGridView1_RowStateChanged(object sender, DataGridViewRowStateChangedEventArgs e)
        {
            e.Row.HeaderCell.Value = string.Format("{0}", e.Row.Index + 1);
        }
    }
}
